/*     */ package com.qmsk.business.store.salebillback.controller;
/*     */ 
/*     */ import com.qmsk.business.bussBill.bussBill.dao.BussBillDao;
/*     */ import com.qmsk.business.member.bussbillpaycheck.dao.BussBillPayCheckDao;
/*     */ import com.qmsk.business.member.member.dao.MemberDAO;
/*     */ import com.qmsk.business.member.memberAct.MemberActConst;
/*     */ import com.qmsk.business.member.memberCashCoupBill.dao.MemberCashCouponBillDao;
/*     */ import com.qmsk.business.member.memberCashCoupConsumeRecord.dao.MemberCashCouponConsumeRecordDAO;
/*     */ import com.qmsk.business.member.memberCashCoupDetail.dao.MemberCashCouponDetailDAO;
/*     */ import com.qmsk.business.member.memberDepositConsumeRecord.dao.MemberDepositConsumeRecordDAO;
/*     */ import com.qmsk.business.member.memberIntegralBill.dao.MemberIntegralBillDao;
/*     */ import com.qmsk.business.member.memberIntegralConsumeRecord.dao.MemberIntegralConsumeRecordDAO;
/*     */ import com.qmsk.business.member.memberIntegralDetail.dao.MemberIntegralDetailDAO;
/*     */ import com.qmsk.business.member.memberLog.dao.MemberLogDAO;
/*     */ import com.qmsk.business.member.memberdepositbill.dao.MemberDepositBillDAO;
/*     */ import com.qmsk.business.member.shopMember.dao.ShopMemberDAO;
/*     */ import com.qmsk.business.shopList.ShopMap;
/*     */ import com.qmsk.business.store.instockbill.service.InStockBillService;
/*     */ import com.qmsk.business.store.salebill.dao.SaleBillDao;
/*     */ import com.qmsk.business.store.salebillback.dao.SaleBillBackDAO;
/*     */ import com.qmsk.business.store.salebillpay.dao.SaleBillPayDAO;
/*     */ import com.qmsk.business.store.saledetail.dao.SaleDetailDao;
/*     */ import com.qmsk.session.UserSessionInfo;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadManyRows;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.http.HttpGsonPtResponseUtils;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"saleBillBack"})
/*     */ public class SaleBillBackController
/*     */ {
/*  67 */   private static final Logger logger = Logger.getLogger(SaleBillBackController.class);
/*     */ 
/*     */   @Autowired
/*     */   private BussBillPayCheckDao bussbillpaycheckDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDAO memberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDepositConsumeRecordDAO depositConsumeRecordDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralDetailDAO integralDetailDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberLogDAO memberLogDAO;
/*     */ 
/*     */   @Autowired
/*     */   private ShopMemberDAO shopMemberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralConsumeRecordDAO integralConsumeRecordDAO;
/*     */ 
/*     */   @Autowired
/*     */   private SaleBillBackDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private SaleBillDao saleBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private BussBillDao bussBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private SaleBillPayDAO saleBillPayDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCashCouponDetailDAO memberCashCouponDetailDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCashCouponConsumeRecordDAO memberCashCouponConsumeRecordDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCashCouponBillDao memberCashCouponBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralBillDao memberIntegralBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDepositBillDAO memberDepositBillDAO;
/*     */ 
/*     */   @Autowired
/*     */   private SaleDetailDao saleDetailDao;
/*     */ 
/*     */   @Autowired
/*     */   private InStockBillService inStockBillService;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/stId/paid/date/sum"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getSumShopIdStIdDate(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId)
/*     */   {
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/paid/date/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListShopIdStIdDate(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 166 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 168 */       Map params = new HashMap();
/* 169 */       MapUtils.addToMap(params, "shopId", shopId);
/* 170 */       MapUtils.addToMap(params, "billNo", 
/* 171 */         RequestUtils.getString(request, "billNo"));
/* 172 */       MapUtils.addToMap(params, "dtPaidStart", 
/* 173 */         RequestUtils.getString(request, "dtPaidStart"));
/* 174 */       MapUtils.addToMap(params, "dtPaidEnd", 
/* 175 */         RequestUtils.getString(request, "dtPaidEnd"));
/* 176 */       MapUtils.addToMap(params, "status", 
/* 177 */         RequestUtils.getInt(request, "status"));
/* 178 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(params, nPageIdx, 
/* 179 */         nPageSize);
/* 180 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 182 */       logger.error(e);
/* 183 */       ResponseUtils.setErrorMsgResponse(
/* 184 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insertList(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/* 222 */       int nResult = 0;
/* 223 */       ParserDataSetJson p = new ParserDataSetJson(
/* 224 */         request.getParameter("data"));
/* 225 */       nResult = this.dao.applyUpdates(p);
/* 226 */       if ((nResult > 0) || ((p != null) && (!(p.isExistsRows())))) {
/* 227 */         ParserDataSetJson pCheck = 
/* 228 */           ParserDataSetJson.fromString(RequestUtils.getString(request, "chkPay"));
/* 229 */         nResult += this.bussbillpaycheckDao.applyUpdates(pCheck);
/* 230 */         if (nResult > 0)
/* 231 */           DbConnection.commit();
/*     */         else {
/* 233 */           DbConnection.rollback();
/*     */         }
/*     */       }
/* 236 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 237 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 238 */         response);
/*     */     } catch (Exception e) {
/* 240 */       DbConnection.rollback();
/* 241 */       logger.error(e);
/* 242 */       ResponseUtils.setErrorMsgResponse(
/* 243 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 244 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"repaid/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void repaidCustId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/* 261 */     Long id = RequestUtils.getLong(request, "id");
/*     */ 
/* 263 */     String userName = UserSessionInfo.getUserNameOfRequest(request);
/* 264 */     String billNo = null;
/* 265 */     String inNo = null;
/* 266 */     int nResult = 0;
/*     */     try {
/* 268 */       if (id == null) {
/* 269 */         ResponseUtils.setErrorMsgResponse("数据不为空", response);
/* 270 */         return;
/*     */       }
/* 272 */       GsonHeadOneRow g = this.saleBillDao.getOneRowOfId(id);
/* 273 */       if (g != null) {
/* 274 */         billNo = (String)g.getValueOfName("billNo");
/* 275 */         int status = ObjectComm.objectToInteger(g
/* 276 */           .getValueOfName("status")).intValue();
/*     */ 
/* 277 */         if (status == 4) {
/* 278 */           ResponseUtils.setErrorMsgResponse("该单据已审核", response);
/* 279 */           return; }
/* 280 */         if (status < 2) {
/* 281 */           ResponseUtils.setErrorMsgResponse("该单据未付款", response);
/* 282 */           return;
/*     */         }
/*     */ 
/* 285 */         nResult = this.saleBillDao.updateStatusOfId(id, 3);
/*     */ 
/* 287 */         if (nResult > 0) {
/* 288 */           g.delHead(new String[] { "StaName", "cashAmt", "regAmt", 
/* 289 */             "depstAmt", "groupAmt", "cashCoupAmt", "bnkAmt", 
/* 290 */             "chkAmt", "viceAmt", "sUserId", 
/* 291 */             "sUserName" });
/* 292 */           nResult = this.dao.insertGsonHeadOneRow(g);
/*     */         }
/*     */ 
/* 295 */         if (nResult > 0) {
/* 296 */           inNo = this.inStockBillService.getInNo(shopId);
/* 297 */           String[] head = { "shopId", "inTpId", 
/* 298 */             "inNo", "linkNo", "maker", "makeDate", 
/* 299 */             "status", "inDate" };
/* 300 */           Object[] data = { shopId, Integer.valueOf(1), inNo, billNo, 
/* 301 */             userName, new Date(), Integer.valueOf(1), new Date() };
/* 302 */           GsonHeadManyRows m = this.saleDetailDao
/* 303 */             .getManyRowsGoodsDetailOfSaleId(id);
/* 304 */           nResult = this.inStockBillService.insertOutBill(
/* 305 */             new GsonHeadOneRow(head, data), m).intValue();
/*     */ 
/* 306 */           if (nResult > 0) {
/* 307 */             Long inId = this.inStockBillService.getLastId();
/* 308 */             nResult = this.inStockBillService.check(inId, response).intValue();
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 313 */         if (nResult > 0)
/*     */         {
/* 315 */           nResult = this.bussBillDao.deleteBussBillOfBillNo(billNo);
/*     */         }
/*     */ 
/* 318 */         if (nResult > 0) {
/* 319 */           nResult = this.saleBillDao.updateStatusOfId(id, 1);
/*     */         }
/*     */       }
/* 322 */       if (nResult > 0)
/* 323 */         DbConnection.commit();
/*     */       else {
/* 325 */         DbConnection.rollback();
/*     */       }
/* 327 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 328 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 329 */         response);
/*     */     } catch (Exception e) {
/* 331 */       DbConnection.rollback();
/* 332 */       logger.error(e);
/* 333 */       ResponseUtils.setErrorMsgResponse(
/* 334 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 335 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"repaid/shopId/{shopId}/member"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void repaidMember(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/* 352 */     Long id = RequestUtils.getLong(request, "id");
/* 353 */     String billNo = null;
/* 354 */     String inNo = null;
/* 355 */     int nResult = 0;
/*     */     try {
/* 357 */       if (id == null) {
/* 358 */         ResponseUtils.setErrorMsgResponse("数据不为空", response);
/* 359 */         return;
/*     */       }
/* 361 */       Long userId = UserSessionInfo.getIntUserIdOfRequest(request);
/* 362 */       String userName = UserSessionInfo.getUserNameOfRequest(request);
/* 363 */       GsonHeadOneRow g = this.saleBillDao.getOneRowOfId(id);
/* 364 */       if (g != null) {
/* 365 */         int status = ObjectComm.objectToInteger(g
/* 366 */           .getValueOfName("status")).intValue();
/*     */ 
/* 367 */         if (status == 4) {
/* 368 */           ResponseUtils.setErrorMsgResponse("该单据已审核", response);
/* 369 */           return; }
/* 370 */         if (status < 2) {
/* 371 */           ResponseUtils.setErrorMsgResponse("该单据未付款", response);
/* 372 */           return;
/*     */         }
/*     */ 
/* 375 */         nResult = this.saleBillDao.updateStatusOfId(id, 3);
/*     */ 
/* 377 */         if (nResult > 0) {
/* 378 */           Long memberId = ObjectComm.objectToLong(g
/* 379 */             .getValueOfName("MemberID"));
/* 380 */           billNo = (String)g.getValueOfName("billNo");
/* 381 */           nResult = paidDetailOfbsbill(id, shopId, memberId, billNo, 
/* 382 */             userId, userName, request, response);
/*     */         }
/*     */ 
/* 386 */         if (nResult > 0) {
/* 387 */           g.delHead(new String[] { "StaName", "cashAmt", "regAmt", 
/* 388 */             "depstAmt", "groupAmt", "cashCoupAmt", "bnkAmt", 
/* 389 */             "chkAmt", "viceAmt", "sUserId", 
/* 390 */             "sUserName" });
/* 391 */           nResult = this.dao.insertGsonHeadOneRow(g);
/*     */         }
/*     */ 
/* 394 */         if (nResult > 0) {
/* 395 */           inNo = this.inStockBillService.getInNo(shopId);
/* 396 */           String[] head = { "shopId", "inTpId", 
/* 397 */             "inNo", "linkNo", "maker", "makeDate", 
/* 398 */             "status", "inDate" };
/* 399 */           Object[] data = { shopId, Integer.valueOf(1), inNo, billNo, 
/* 400 */             userName, new Date(), Integer.valueOf(1), new Date() };
/* 401 */           GsonHeadManyRows m = this.saleDetailDao
/* 402 */             .getManyRowsGoodsDetailOfSaleId(id);
/* 403 */           nResult = this.inStockBillService.insertOutBill(
/* 404 */             new GsonHeadOneRow(head, data), m).intValue();
/*     */ 
/* 405 */           if (nResult > 0) {
/* 406 */             Long inId = this.inStockBillService.getLastId();
/* 407 */             nResult = this.inStockBillService.check(inId, response).intValue();
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 412 */         if (nResult > 0)
/*     */         {
/* 414 */           nResult = this.bussBillDao.deleteBussBillOfBillNo(billNo);
/*     */         }
/*     */ 
/* 417 */         if (nResult > 0) {
/* 418 */           nResult = this.saleBillDao.updateStatusOfId(id, 1);
/*     */         }
/*     */       }
/* 421 */       if (nResult > 0)
/* 422 */         DbConnection.commit();
/*     */       else {
/* 424 */         DbConnection.rollback();
/*     */       }
/* 426 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 427 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 428 */         response);
/*     */     } catch (Exception e) {
/* 430 */       DbConnection.rollback();
/* 431 */       logger.error(e);
/* 432 */       ResponseUtils.setErrorMsgResponse(
/* 433 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 434 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private int paidDetailOfbsbill(Long id, Long shopId, Long memberId, String billNo, Long userId, String userName, HttpServletRequest request, HttpServletResponse response)
/*     */     throws SQLException, Exception
/*     */   {
/* 442 */     int nResult = 0;
/* 443 */     GsonHeadOneRow r = this.saleBillPayDAO.getGsonOneRowOfId(id);
/* 444 */     if (r == null) {
/* 445 */       return -1;
/*     */     }
/*     */ 
/* 448 */     Double depositAmt = ObjectComm.objectToDouble(
/* 449 */       r.getValueOfName("depstAmt"), Double.valueOf(0.0D));
/*     */ 
/* 451 */     Double cashCouponAmt = ObjectComm.objectToDouble(
/* 452 */       r.getValueOfName("cashCoupAmt"), Double.valueOf(0.0D));
/*     */ 
/* 454 */     Map params = new HashMap();
/* 455 */     MapUtils.addToMap(params, "depsitAmt", depositAmt);
/* 456 */     MapUtils.addToMap(params, "cashCoupAmt", cashCouponAmt);
/* 457 */     MapUtils.addToMap(params, "memberId", memberId);
/* 458 */     MapUtils.addToMap(params, "shopId", shopId);
/* 459 */     nResult = this.shopMemberDAO.updateDopositCashCoupInc(params);
/* 460 */     params.remove("shopId");
/* 461 */     nResult = this.memberDAO.updateDopositCashCoupInc(params);
/*     */ 
/* 463 */     if (nResult > 0)
/*     */     {
/* 465 */       Integer intr = Integer.valueOf(this.memberIntegralBillDao.getIntrOfBillNo(billNo));
/*     */ 
/* 467 */       Integer cashCoup = this.memberCashCouponBillDao
/* 468 */         .getCashCoupOfBillNo(billNo);
/* 469 */       params = new HashMap();
/* 470 */       MapUtils.addToMap(params, "intr", intr);
/* 471 */       MapUtils.addToMap(params, "cashCoup", cashCoup);
/* 472 */       MapUtils.addToMap(params, "memberId", memberId);
/* 473 */       MapUtils.addToMap(params, "shopId", shopId);
/* 474 */       nResult = this.shopMemberDAO.updateIntrCashCoupSub(params);
/* 475 */       params.remove("shopId");
/* 476 */       nResult = this.memberDAO.updateIntrCashCoupSub(params);
/*     */ 
/* 479 */       nResult = nResult + this.memberDepositBillDAO
/* 479 */         .deleteHeadData(new String[] { "BillNo" }, new Object[] { billNo });
/*     */ 
/* 481 */       nResult = nResult + this.depositConsumeRecordDAO
/* 481 */         .deleteHeadData(new String[] { "WorkNo" }, new Object[] { billNo });
/* 482 */       GsonHeadManyRows m = this.memberIntegralBillDao.getIdOfBussNo(billNo);
/*     */       int i;
/* 483 */       if ((m != null) && (m.getDataLength() > 0)) {
/* 484 */         for (i = 0; i < m.getDataLength(); ++i)
/*     */         {
/* 487 */           nResult = nResult + this.integralDetailDAO
/* 487 */             .deleteHeadData(new String[] { "BillID" }, 
/* 487 */             new Object[] { m.getValueOfName("id", i) });
/*     */         }
/*     */       }
/*     */ 
/* 491 */       nResult = nResult + this.memberIntegralBillDao
/* 491 */         .deleteHeadData(new String[] { "BillNo" }, new Object[] { billNo });
/*     */ 
/* 493 */       nResult = nResult + this.integralConsumeRecordDAO
/* 493 */         .deleteHeadData(new String[] { "WorkNo" }, new Object[] { billNo });
/*     */ 
/* 495 */       m = this.memberCashCouponBillDao.getIdOfBussNo(billNo);
/* 496 */       if ((m != null) && (m.getDataLength() > 0)) {
/* 497 */         for (i = 0; i < m.getDataLength(); ++i)
/*     */         {
/* 500 */           nResult = nResult + this.memberCashCouponDetailDAO
/* 500 */             .deleteHeadData(new String[] { "BillID" }, 
/* 500 */             new Object[] { m.getValueOfName("id", i) });
/*     */         }
/*     */       }
/*     */ 
/* 504 */       nResult = nResult + this.memberCashCouponBillDao
/* 504 */         .deleteHeadData(new String[] { "BillNo" }, new Object[] { billNo });
/*     */ 
/* 506 */       nResult = nResult + this.memberCashCouponConsumeRecordDAO
/* 506 */         .deleteHeadData(new String[] { "WorkNo" }, new Object[] { billNo });
/*     */     }
/* 508 */     GsonHeadOneRow pa = this.shopMemberDAO.getPaidOneRowOfMemberId(memberId, 
/* 509 */       shopId);
/* 510 */     if ((pa != null) && (pa.getDataLength() > 0)) {
/* 511 */       Long outId = this.memberDAO.getOutMIdOfId(memberId);
/* 512 */       if ((outId != null) && (outId.longValue() > 0L)) {
/* 513 */         pa.autoAddHeadData("shopId", 
/* 514 */           ShopMap.getOutIdOfShopId(shopId));
/* 515 */         String sData = "data=" + 
/* 516 */           pa.objectToJsonStr() + "&" + "id" + 
/* 517 */           "=" + outId;
/* 518 */         String sUrl = "ptmember/editPaid";
/* 519 */         GsonEbRst rst = HttpGsonPtResponseUtils.postPtEbRst(sUrl, 
/* 520 */           sData, response);
/* 521 */         if ((rst == null) || (rst.getState() != 0))
/* 522 */           return -14;
/*     */       }
/*     */     }
/*     */     else {
/* 526 */       return -14;
/*     */     }
/* 528 */     this.memberLogDAO.insertMemberLogBuss(MemberActConst.RPAID, billNo, Double.valueOf(0.0D), 
/* 529 */       Double.valueOf(0.0D), Double.valueOf(0.0D), Double.valueOf(0.0D), memberId, userId, userName);
/*     */ 
/* 531 */     return nResult;
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.salebillback.controller.SaleBillBackController
 * JD-Core Version:    0.5.3
 */